package com.lzh.healthCode.business.controller;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.lzh.healthCode.business.entity.*;
import com.lzh.healthCode.business.service.CjInfoService;
import com.lzh.healthCode.business.service.JgInfoService;
import com.lzh.healthCode.business.service.ZyInfoService;
import com.lzh.healthCode.core.BaseConfig;
import com.lzh.healthCode.utils.UpdAreaEnum;
import com.lzh.healthCode.utils.UpdTypeEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * 接口补录类
 *
 * @author suYanLong
 * @date 2022年07月09日 15:58
 */

@RestController
@RequestMapping("Supplement")
@Slf4j
public class SupplementController extends BaseConfig {

    @Resource
    CjInfoService cjInfoService;

    @GetMapping("sampleReport")
    public String sampleReport(@RequestParam String SAMPLENO) {
        // 测试人员信息上传接口 【参数】
        List<CjInfoBean> selectSupp = cjInfoService.getSelectSupp(SAMPLENO);
        for (CjInfoBean cjInfoBean : selectSupp) {
            commonService.uploadSampleReport(UpdAreaEnum.UPD_AREA_TYPE_1, UpdTypeEnum.UPD_TYPE_2, cjInfoBean);
//            commonService.uploadSampleReport(UpdAreaEnum.UPD_AREA_TYPE_2, UpdTypeEnum.UPD_TYPE_2, cjInfoBean);
        }
        return "sampleReport";
    }

    @Resource
    ZyInfoService zyInfoService;

    @GetMapping("transportReport")
    public String transportReport(@RequestParam String SAMPLENO) {

        List<ZyInfoBean> selectSupp = zyInfoService.getSelectSupp(SAMPLENO);
        for (ZyInfoBean zyInfoBean : selectSupp) {
            commonService.uploadtransportReport(UpdAreaEnum.UPD_AREA_TYPE_1, UpdTypeEnum.UPD_TYPE_2, zyInfoBean);
//            commonService.uploadtransportReport(UpdAreaEnum.UPD_AREA_TYPE_2, UpdTypeEnum.UPD_TYPE_2, zyInfoBean);
        }

//      ResultBean resultBean1 = httpRequestConfig.sendPostProvince(healthCodeInfo.getTransportReportUrl(), jsonArray.toJSONString());
        return "transportReport";
    }

    @Resource
    JgInfoService jgInfoService;

    @GetMapping("checkResultReport")
    public String checkResultReport(@RequestParam String SAMPLENO) {
        List<JgInfoBean> selectSupp = jgInfoService.getSelectSupp(SAMPLENO);
//        int i = 0;
        for (JgInfoBean jgInfoBean : selectSupp) {
            commonService.uploadcheckResultReport(UpdAreaEnum.UPD_AREA_TYPE_1, UpdTypeEnum.UPD_TYPE_2,jgInfoBean);
//            commonService.uploadcheckResultReport(UpdAreaEnum.UPD_AREA_TYPE_2, UpdTypeEnum.UPD_TYPE_2,jgInfoBean);

//            }
        }
//        jgInfoService.updateErrorCount(i);
//        System.out.println(i);
//      ResultBean resultBean1 = httpRequestConfig.sendPostProvince(healthCodeInfo.getTransportReportUrl(), jsonArray.toJSONString());
        return "checkResultReport";
    }

    @GetMapping("areaList")
    public String areaList() {
        JSONObject jsonObject = new JSONObject();
        JSONArray jsonArray = new JSONArray();
        jsonArray.add(jsonObject);
        jsonArray.toJSONString();
        ResultBean resultBean = httpRequestConfig.sendGet(healthCodeInfo.getAreaListUrl(), jsonArray.toJSONString());
        return "areaList";
    }

}
